package com.yimi.yinhepda.entity.response;

import com.yimi.yinhepda.utils.Common;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author 000432
 * @date 2017/4/6
 * PDA获取装车任务单号列表  主单信息
 */
public class QueryUnLoadDetailBillcode implements Serializable {
    /**
     * 车线任务号
     */
    private String taskNo;
    /**
     * 运单号/包号
     */
    private String waybillNo;
    /**
     * 开单件数
     */
    private Integer srcPiecesNum;
    /**
     * 交接件数
     */
    private Integer piecesNum;
    /**
     * 重量
     */
    private BigDecimal weight;
    /**
     * 体积
     */
    private BigDecimal volume;
    /**
     * 计费重量
     */
    private BigDecimal chargedWeight;
    /**
     * 运单路由
     */
    private String waybillRoute;
    /**
     * 包号
     */
    private String packageNo;
    /**
     * 到达货区
     */
    private String areaCode;
    /**
     * 单据类型：1 运单，2 包
     */
    private Integer billType;
    /**
     * 配载单号
     */
    private String stowageNo;
    /**
     * 车牌号
     */
    private String carNo;
    /**
     * 是否是大票货
     */
    private boolean isBigTicket = false;
    /**
     * 强扫标记   空不是强扫   2是强扫
     */
    private transient String remark = "";
    /**
     * 运单子单集合
     */
    private List<QueryLoadDetailChildBillcode> childList;
    private boolean isCheck;
    /**
     * 托盘绑定数
     */
    private int forkLiftNum;
    /**
     * 下一站
     */
    private String nextDeptCode;
    private String nextDeptName;
    /**
     * 托盘任务号
     */
    private String forliftNo;
    /**
     * 绑定标识 1-第一次绑定 2-第二次绑定
     */
    private int cancleStatu;
    /**
     * 输入方式 1-PDA扫描输入,2-手动输入
     */
    private int inputType;
    /**
     * 扫描时间
     */
    private String operTime;
    /**
     * 必走货字段 1-必走货，2-串货，3-标准货,4-跨越
     */
    private String goodsPriority;
    /**
     * 产品类型：CP24-时，CP13-优
     */
    private String productType;
    /**
     * 一级排序：红>黄>白>绿,getType
     */
    private int firstSort;
    /**
     * 二级排序： 时>比>优>串>标
     */
    private int secondSort = Common.GOODSP_RIORITY_DEFAULT;
    /**
     * 必走货提醒
     */
    private boolean isBiRemind;
    /**
     * 优速运单是否扫描标志
     */
    private boolean isUcScan;
    /**
     * 运单类型:1-正常单  2-整车单,3-外传单 4-内转单 5-退货单,  6-签回单
     */
    private String waybillType;
    /**
     * 上下一站
     */
    private String relationDeptCode;
    /**
     * 上下一站名称
     */
    private String relationDeptName;
    /**
     * 上下一站部门类型
     */
    private Integer relationDeptType;

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public QueryUnLoadDetailBillcode(String stowageNo, String remark, String carNo, Integer billType, String areaCode, String packageNo,
                                     String waybillRoute, BigDecimal volume, BigDecimal chargedWeight, BigDecimal weight, Integer piecesNum, Integer srcPiecesNum,
                                     String waybillNo) {
        this.stowageNo = stowageNo;
        this.remark = remark;
        this.carNo = carNo;
        this.billType = billType;
        this.areaCode = areaCode;
        this.packageNo = packageNo;
        this.waybillRoute = waybillRoute;
        this.volume = volume;
        this.chargedWeight = chargedWeight;
        this.weight = weight;
        this.piecesNum = piecesNum;
        this.srcPiecesNum = srcPiecesNum;
        this.waybillNo = waybillNo;
    }

    public QueryUnLoadDetailBillcode() {
    }

    public String getTaskNo() {
        return taskNo;
    }

    public void setTaskNo(String taskNo) {
        this.taskNo = taskNo;
    }

    public String getRelationDeptCode() {
        return relationDeptCode;
    }

    public void setRelationDeptCode(String relationDeptCode) {
        this.relationDeptCode = relationDeptCode;
    }

    public String getRelationDeptName() {
        return relationDeptName;
    }

    public void setRelationDeptName(String relationDeptName) {
        this.relationDeptName = relationDeptName;
    }

    public Integer getRelationDeptType() {
        return relationDeptType;
    }

    public void setRelationDeptType(Integer relationDeptType) {
        this.relationDeptType = relationDeptType;
    }

    public String getWaybillType() {
        return waybillType;
    }

    public void setWaybillType(String waybillType) {
        this.waybillType = waybillType;
    }

    public boolean isUcScan() {
        return isUcScan;
    }

    public void setUcScan(boolean ucScan) {
        isUcScan = ucScan;
    }

    public boolean isBiRemind() {
        return isBiRemind;
    }

    public void setBiRemind(boolean biRemind) {
        isBiRemind = biRemind;
    }

    public int getFirstSort() {
        return firstSort;
    }

    public void setFirstSort(int firstSort) {
        this.firstSort = firstSort;
    }

    public int getSecondSort() {
        return secondSort;
    }

    public void setSecondSort(int secondSort) {
        this.secondSort = secondSort;
    }

    public String getGoodsPriority() {
        return goodsPriority;
    }

    public void setGoodsPriority(String goodsPriority) {
        this.goodsPriority = goodsPriority;
    }

    public String getProductType() {
        return productType;
    }

    public void setProductType(String productType) {
        this.productType = productType;
    }

    public String getOperTime() {
        return operTime;
    }

    public void setOperTime(String operTime) {
        this.operTime = operTime;
    }

    public int getInputType() {
        return inputType;
    }

    public void setInputType(int inputType) {
        this.inputType = inputType;
    }

    public int getCancleStatu() {
        return cancleStatu;
    }

    public void setCancleStatu(int cancleStatu) {
        this.cancleStatu = cancleStatu;
    }

    public String getForliftNo() {
        return forliftNo;
    }

    public void setForliftNo(String forliftNo) {
        this.forliftNo = forliftNo;
    }

    public int getForkLiftNum() {
        return forkLiftNum;
    }

    public void setForkLiftNum(int forkLiftNum) {
        this.forkLiftNum = forkLiftNum;
    }

    public String getNextDeptCode() {
        return nextDeptCode;
    }

    public void setNextDeptCode(String nextDeptCode) {
        this.nextDeptCode = nextDeptCode;
    }

    public String getNextDeptName() {
        return nextDeptName;
    }

    public void setNextDeptName(String nextDeptName) {
        this.nextDeptName = nextDeptName;
    }

    public boolean isCheck() {
        return isCheck;
    }

    public void setCheck(boolean check) {
        isCheck = check;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getStowageNo() {
        return stowageNo;
    }

    public void setStowageNo(String stowageNo) {
        this.stowageNo = stowageNo;
    }

    public String getCarNo() {
        return carNo;
    }

    public void setCarNo(String carNo) {
        this.carNo = carNo;
    }

    public String getWaybillNo() {
        return waybillNo;
    }

    public void setWaybillNo(String waybillNo) {
        this.waybillNo = waybillNo;
    }

    public Integer getSrcPiecesNum() {
        if (srcPiecesNum == null) {
            srcPiecesNum = 0;
        }
        return srcPiecesNum;
    }

    public void setSrcPiecesNum(Integer srcPiecesNum) {
        this.srcPiecesNum = srcPiecesNum;
    }

    public Integer getPiecesNum() {
        if (piecesNum == null) {
            piecesNum = 0;
        }
        return piecesNum;
    }

    public void setPiecesNum(Integer piecesNum) {
        this.piecesNum = piecesNum;
    }

    public BigDecimal getWeight() {
        if (weight == null) {
            weight = BigDecimal.ZERO;
        }
        return weight;
    }

    public void setWeight(BigDecimal weight) {
        this.weight = weight;
    }

    public BigDecimal getVolume() {
        if (volume == null) {
            volume = BigDecimal.ZERO;
        }
        return volume;
    }

    public void setVolume(BigDecimal volume) {
        this.volume = volume;
    }

    public BigDecimal getChargedWeight() {
        if (chargedWeight == null) {
            chargedWeight = BigDecimal.ZERO;
        }
        return chargedWeight;
    }

    public void setChargedWeight(BigDecimal chargedWeight) {
        this.chargedWeight = chargedWeight;
    }

    public String getWaybillRoute() {
        return waybillRoute;
    }

    public void setWaybillRoute(String waybillRoute) {
        this.waybillRoute = waybillRoute;
    }

    public String getPackageNo() {
        return packageNo;
    }

    public void setPackageNo(String packageNo) {
        this.packageNo = packageNo;
    }

    public String getAreaCode() {
        return areaCode;
    }

    public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }

    public Integer getBillType() {
        if (billType == null) {
            billType = 0;
        }
        return billType;
    }

    public void setBillType(Integer billType) {
        this.billType = billType;
    }

    public List<QueryLoadDetailChildBillcode> getChildList() {
        return childList;
    }

    public void setChildList(List<QueryLoadDetailChildBillcode> childList) {
        this.childList = childList;
    }

    /**
     * 获得已扫数量
     */
    public int getScanCount() {
        if (childList == null || childList.size() == 0) {
            return 0;
        }
        int count = 0;
        for (QueryLoadDetailChildBillcode item : childList) {
            if (item.getFlag() == 1) {
                count++;
            }
        }
        return count;
    }

    /**
     * 获取已扫描的托盘绑定数量
     */
    public int getPalletBindScanCount() {
        if (childList == null || childList.size() == 0) {
            return 0;
        }
        int count = 0;
        for (QueryLoadDetailChildBillcode item : childList) {
            if (item.getPalletBindFlag() == 1) {
                count++;
            }
        }
        return count;
    }

    /**
     * 差异=扫描-交接   卸车
     */
    public int getDifference() {
        if ("2".equals(waybillType)) {
            //整车单
            if (getScanCount() > 0) {
                return 0;
            } else {
                return -srcPiecesNum;
            }
        } else {
//            if ("2".equals(remark)) {
//                return 1;
//            } else {
                return getScanCount() - (piecesNum == null ? 0 : piecesNum);
//            }
        }
    }

    public int getType() {
        int dif = getDifference();
        if (getScanCount() == 0) {
            //白色
            return 1;
        } else if (dif < 0) {
            //红色
            return 0;
        } else if (dif > 0) {
            //黄色
            return 2;
        } else {
            //绿色
            return 3;
        }
    }

    public boolean isBigTicket() {
        return isBigTicket;
    }

    public void setBigTicket(boolean mBigTicket) {
        isBigTicket = mBigTicket;
    }

    public static QueryUnLoadDetailBillcode parse(QueryLoadDetailBillcode mQueryLoadDetailBillcode) {
        QueryUnLoadDetailBillcode mQueryUnLoadDetailBillcode =
                new QueryUnLoadDetailBillcode(mQueryLoadDetailBillcode.getStowageNo(), mQueryLoadDetailBillcode.getRemark(),
                        mQueryLoadDetailBillcode.getCarNo(), mQueryLoadDetailBillcode.getBillType(), mQueryLoadDetailBillcode.getAreaCode(),
                        mQueryLoadDetailBillcode.getPackageNo(), mQueryLoadDetailBillcode.getWaybillRoute(), mQueryLoadDetailBillcode.getVolume(),
                        mQueryLoadDetailBillcode.getChargedWeight(), mQueryLoadDetailBillcode.getWeight(), mQueryLoadDetailBillcode.getPiecesNum(),
                        mQueryLoadDetailBillcode.getSrcPiecesNum(), mQueryLoadDetailBillcode.getWaybillNo());
        mQueryUnLoadDetailBillcode.setChildList(mQueryLoadDetailBillcode.getChildList());
        return mQueryUnLoadDetailBillcode;
    }
}
